<script setup>
import { onMounted, reactive, ref } from "vue";
import { Map, View } from "ol";
import TileLayer from "ol/layer/Tile";
import { XYZ } from "ol/source";
import { fromLonLat } from "ol/proj";
defineProps({
  msg: String,
});
let map = reactive("");
onMounted(() => {
  initMap();
});
let initMap = () => {
  map = new Map({
    target: "map",//挂载视图的容器
    layers: [
      //图层
      new TileLayer({
        source: new XYZ({
          url: "http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}",
          wrapX: false,
        }),
      }), 
    ],
    //视图
    view: new View({
      // center:[114.305469,30.592876],
      // center: fromLonLat([114.08, 30.59]),//转为经纬度
      zoom: 10,//缩放
      center:[114.305469,30.592876],
      projection:'EPSG:4326'// 经纬度

    }),
  });
};

</script>

<template>
  <div id="map"></div>
</template>

<style scoped>
.read-the-docs {
  color: #888;
}
#map {
  margin: 0;
  width: 100vw;
  height: 100vh;
}
</style>
